
version 15
capture log close
set more off
clear
clear matrix
clear mata

if c(username)=="WB485280" {
		glo rootdir		"C:\Users\wb485280\OneDrive - WBG\radicalization"
		}
if c(username)=="WB382635" {
		glo rootdir		"C:\Users\wb382635\Dropbox\Unemp & daesh"
		}
if c(username)=="WB452275" {
		glo rootdir		"C:\Users\WB452275\Dropbox\Projects\Unemp & daesh"
		}
if c(username)=="sarurchaudhary" {
		glo rootdir		"/Users/sarurchaudhary/Dropbox/Unemp & daesh"
		}
if c(username)=="kartikabhatia" {
			glo rootdir		"/Users/kartikabhatia/Dropbox/Before2019/Unemp & daesh"
			}
			
		glo	datadir     "${rootdir}/Data/Raw data"
		glo outdir		"${rootdir}/Data/Working datasets"
		glo dodir		"${rootdir}/Dofiles"
        
			
			cd "${outdir}"
			

* ------------------------------------------------------------------------------

* Date : March 2021 [Checked Oct 2021]

* Project : Daesh FF Working Paper (The World Bank)

* This is the do file for Tables 1-4 in the main paper

* ------------------------------------------------------------------------------
				
				
********************************************************
*Table 1: Daesh Recruits by country of last residence
********************************************************		


*Get list of countries that are used in regresssions 
	//note  that this includes countries with one recruit, but excludes countries that do not have labor force by educ or educ of fighters
	u "${outdir}/reg_sample.dta", clear
	keep if sample==1
	keep countryname sample
	so countryname
	keep if countryname!=countryname[_n-1]
	tempfile sample
	sa `sample'


*use "${outdir}/finaldata_C.dta", clear 
use "${outdir}/finaldata_C_temp.dta", clear 

		*sample includes 3547 fighters: all fighters in entry form that have country of residence; regardless of whether they have educ or not; fighters in Iraq/Syria are dropped later before doing taable; countries without UE or labor force are kept but starred 


	*Spread pew muslim from 2010 to 2013
		tsset ctry year
			foreach v in pew_muslims_n  {
			replace `v'=L1.`v' if  `v'==.
			replace `v'=F1.`v' if  `v'==.
			replace `v'=L2.`v' if  `v'==.
			replace `v'=F2.`v' if  `v'==.
			replace `v'=L3.`v' if  `v'==.
			replace `v'=F3.`v' if  `v'==.			
			}
	
	keep if year==2013	
	cap drop _merge
	cap drop quart_dist
	*merge m:1 ctry using "${outdir}/quartile_split.dta"
	
	drop if missing(isis_nfighter_resid)
	drop if countryname== "All" | countryname=="Syrian Arab Republic" | countryname=="Iraq"
	xtile quart_dist = dist_tosyria,   nq(4) // create quartiles of distance
	
	merge 1:1 countryname using `sample'
		
	gen region_wb = ""
	replace region_wb = "East Asia" 					if reg_eastasia
	replace region_wb = "South Asia" 					if reg_southasia
	replace region_wb = "Europe and Central Asia" 		if reg_eca
	replace region_wb = "Middle East and North Africa" 	if reg_mena
	replace region_wb = "Ltin America and Carribean" 	if reg_lac
	replace region_wb = "Africa" 						if reg_africa
	
	gen region_gallup = ""
	replace region_gallup = "Europe" 				if g_region_europe
	replace region_gallup = "Fmr Soviet" 			if g_region_formersoviet
	replace region_gallup = "Asia" 					if g_region_asia
	replace region_gallup = "Americas" 				if g_region_americas
	replace region_gallup = "MENA" 					if g_region_mena
	replace region_gallup = "SSA" 					if g_region_subafrica
	

	gsort dist_tosyria
	
	gen lab_1000 = lab_total/1000
	gen lab_mn = lab_1000/1000

	egen total_fighter = total(isis_nfighter_resid)

	gen fighter_per_mn_muslims = 1000000*isis_nfighter_resid/ pew_muslims_n
	

	replace countryname = "Kyrgyzstan" if countryname == "Kyrgyz Republic"
	replace countryname = "Russia" if countryname == "Russian Federation"
	replace countryname = "Britain" if countryname == "United Kingdom"
	replace countryname = "Macedonia" if countryname == "Macedonia, FYR"
	replace countryname = "Macedonia" if countryname == "Macedonia, FYR"
	replace countryname = "Iran" if countryname == "Iran, Islamic Rep."
	replace countryname = "Egypt" if countryname == "Egypt, Arab Rep."
	replace countryname = "Bosnia" if countryname == "Bosnia and Herzegovina"
	replace countryname = "TrinidadTobago" if countryname == "Trinidad and Tobago"
	replace countryname=countryname+"*" if sample!=1 & countryname!="All"
	 
	keep countryname dist_tosyria region_gallup gdp_pc pew_muslims_pct ///
	lab_mn isis_nfighter_resid fighter_per_mn_muslims quart_dist

	order countryname region_gallup isis_nfighter_resid fighter_per_mn_muslims ///
	dist_tosyria quart_dist gdp_pc lab_mn pew_muslims_pct 
	
	local num_obs `=_N'
	set obs  `=`num_obs'+2'	
	
	foreach var of varlist isis_nfighter_resid - pew_muslims_pct{
		summ `var'
		local mean `r(mean)'
		local sd `r(sd)'

		replace `var' = `mean' if _n== `num_obs'+1
		replace `var' = `sd' if _n== `num_obs'+2
	}

	replace countryname = "All" if _n== `num_obs'+1 
	replace countryname = "All" if _n== `num_obs'+2 

	replace region_gallup = "Mean" if _n== `num_obs'+1 
	replace region_gallup = "St. Dev" if _n== `num_obs'+2 

	gen rank = 1 if _n== `num_obs'+1  
	replace rank = 2 if _n== `num_obs'+2  
	replace rank = 9 if _n<= `num_obs'

	gsort rank dist_tosyria
	drop rank

	foreach var of varlist isis_nfighter_resid - pew_muslims_pct {
		replace `var' = int(10*`var'+sign(10*`var')/2)/10
	}

	format isis_nfighter_resid fighter_per_mn_muslims dist_tosyria lab_mn gdp_pc pew_muslims_pct %5.1fc

	*texsave using countries_temp.tex,  replace	
	preserve
	keep if _n<=32
	dataout ,save(countries_data1)  tex  replace
	restore
	
	preserve
	keep if _n>32
	dataout ,save(countries_data2)  tex  replace
	restore
	
	
	foreach num of numlist 1/2{
		
		filefilter countries_data`num'.tex countries_data`num'a.tex, replace ///
		from("\BSdocumentclass[]{article}") to("")	
		
		filefilter countries_data`num'a.tex countries_data`num'b.tex, replace ///
		from("\BSsetlength{\BSpdfpagewidth}{8.5in} \BSsetlength{\BSpdfpageheight}{11in}") to("")	
		
		filefilter countries_data`num'b.tex countries_data`num'c.tex, replace ///
		from("\BSbegin{document}") to("")	
		
		filefilter countries_data`num'c.tex countries_data`num'_1.tex, replace ///
		from("\BSend{document}") to("")		
	}

	local title_old1 countryname 
	local title_old2 region\BS_gallup 
	local title_old3 isis\BS_nfighter\BS_resid 
	local title_old4 fighter\BS_per\BS_mn\BS_muslims 
	local title_old5 dist\BS_tosyria 
	local title_old6 quart\BS_dist
	local title_old7 gdp\BS_pc 
	local title_old8 lab\BS_mn 
	local title_old9 pew\BS_muslims\BS_pct

	local title_new1 Country 
	local title_new2 Region 
	local title_new3 Fighters (#)
	local title_new4 Fighters per million Muslims 
	local title_new5 Distance to Syria (miles)
	local title_new6 Distance Quartile	
	local title_new7 Per-capita GDP (USD) 
	local title_new8 Labor Force (millions) 
	local title_new9 Muslim Proportion (\BS%)

	foreach num of numlist 1/9{
		filefilter countries_data1_`num'.tex countries_data1_`=`num'+1'.tex, replace ///
		from("`title_old`num''") to("`title_new`num''")
		
		filefilter countries_data2_`num'.tex countries_data2_`=`num'+1'.tex, replace ///
		from("`title_old`num''") to("`title_new`num''")
	}
	
	
	/*
	// countries_data1_10 and countries_data2_10 are the final outputs
	For table 1 
	Manually replace this part 
Country & Region & Fighters (#) & Fighters per million Muslims & Distance to Syria (miles) & Distance Quartile & Per-capita GDP (USD) & Labor Force (millions) & Muslim Proportion (\%) \\ \hline
All & Mean & 58.30 & 13.10 & 2081 & 1.900 & 21083 & 37.80 & 51.70 \\
All & St. Dev & 128.5 & 16.40 & 1616 & 1 & 26021 & 121.6 & 43.10 \\


	By this
Country & Region & Number & Fighters per  & Distance  & Distance  & Per-capita & Labor  & Muslim  \\  
 &  & of & million  &  to Syria &  Quartile & GDP  &  Force  & Proportion \\  
 &  & Fighers & Muslims & (miles) & & (USD) & (millions) & (\%) \\ \hline \hline
Mean & All & 58.30 & 13.10 & 2081 & 1.900 & 21083 & 37.80 & 51.70 \\
St. Dev & All & 128.5 & 16.40 & 1616 & 1 & 26021 & 121.6 & 43.10 \\ \hline


	For table 2
	Manually replace this part 
Country & Region & Fighters (#) & Fighters per million Muslims & Distance to Syria (miles) & Distance Quartile & Per-capita GDP (USD) & Labor Force (millions) & Muslim Proportion (\%) \\ \hline
	
	
	By this 
Country & Region & Number & Fighters per  & Distance  & Distance  & Per-capita & Labor  & Muslim  \\  
 &  & of & million  &  to Syria &  Quartile & GDP  &  Force  & Proportion \\  
 &  & Fighers & Muslims & (miles) & & (USD) & (millions) & (\%) \\ \hline \hline
 
	*/
 
	

********************************************************************
*Table 2, Panel A: Summary Statistics of fighter characteristics
********************************************************************

use "${datadir}/ISIS_fighters_new.dta", clear

	drop if Country_resid ==""

	***********************************************************
	***checks for aspirations
	replace Aspiration="." if Aspiration==""
	gen temp1=0
	replace temp1=1 if Aspiration=="."
	drop temp1
	********************

	*           =================
	*           Variables to keep
	*           =================

	g parent = !missing(Number_children)

	set more off
	tab Education, gen(isis_educ_status)
	tab CivilStatus, gen(isis_marital_status)
	tab ReligiousLevel, gen(isis_sharia_knw)
	tab Aspiration, gen (isis_role)
	tab job, gen(isis_emp_status)
	tab Experience, gen(isis_jihad_exp)
	tab Point_entry, gen(isis_entry)
	tab Number_children, gen(isis_num_children)
	tab parent,gen(isis_parent)
	tab Country_origin, gen(isis_nationality)

	*replace isis_nfighter=0 if isis_nfighter==0 | isis_nfighter==. 
	*rename isis_nfighter_resid nisis
				
	rename age isis_age
				
	rename Education isis_education
	recode isis_education (1=1) (2=1) (3=1) (4=2) (5=2) (6=3) (7=4)
	label define ed 1 "primary/noeduc" 2 "secondary" 3 "tertiary" 4 "missing_educ"
	label values isis_education ed
	*egen nisis_educ= count(id), by (Country_resid isis_education)
	*label variable nisis_educ "no. of fighters by education levels per country of residence " 

	g PrimEduc=.
		replace PrimEduc=1 if isis_education==1
		replace PrimEduc=0 if isis_education==2|isis_education==3
		
	g SecEduc=.
		replace SecEduc=1 if isis_education==2
		replace SecEduc=0 if isis_education==1|isis_education==3
		
	g SecTerEduc=.
		replace SecTerEduc=1 if isis_education==2|isis_education==3
		replace SecTerEduc=0 if isis_education==1

	g TerEduc=.
		replace TerEduc=1 if isis_education==3
		replace TerEduc=0 if isis_education==1|isis_education==2

* Creating additional ISIS variables 

	g Married=.
		replace Married=1 if CivilStatus=="Married"
		replace Married=0 if CivilStatus=="Divorced" | CivilStatus=="Single"
		
	g Parent=.
		replace Parent=1 if Number_children>0 & !missing(Number_children)
		replace Parent=0 if Number_children==0 | missing(Number_children)

	g ReligiousPlus=.
		replace ReligiousPlus=1 if ReligiousLevel=="Advanced"
		replace ReligiousPlus=1 if ReligiousLevel=="Intermediary"
		replace ReligiousPlus=0 if ReligiousLevel=="Basic"

	g AdminAspir=.
		replace AdminAspir=1 if Aspir=="Administrative"
		replace AdminAspir=0 if Aspir=="Fighters"
		replace AdminAspir=0 if Aspir=="Suicid_fighter"
		replace AdminAspir=0 if Aspir=="Suicide"

	g FighterAspir=.
		replace FighterAspir=0 if Aspir=="Administrative"
		replace FighterAspir=1 if Aspir=="Fighters"
		replace FighterAspir=0 if Aspir=="Suicid_fighter"
		replace FighterAspir=0 if Aspir=="Suicide"

	g SuicideAspir=.
		replace SuicideAspir=0 if Aspir=="Administrative"
		replace SuicideAspir=0 if Aspir=="Fighters"
		replace SuicideAspir=1 if Aspir=="Suicid_fighter"
		replace SuicideAspir=1 if Aspir=="Suicide"
		
	g AdminAspir_2=0
		replace AdminAspir_2=1 if Aspir=="Administrative"
		replace AdminAspir_2=0 if Aspir=="Fighters"
		replace AdminAspir_2=0 if Aspir=="Suicid_fighter"
		replace AdminAspir_2=0 if Aspir=="Suicide"

	g FighterAspir_2=0
		replace FighterAspir_2=0 if Aspir=="Administrative"
		replace FighterAspir_2=1 if Aspir=="Fighters"
		replace FighterAspir_2=0 if Aspir=="Suicid_fighter"
		replace FighterAspir_2=0 if Aspir=="Suicide"

	g SuicideAspir_2=0
		replace SuicideAspir_2=0 if Aspir=="Administrative"
		replace SuicideAspir_2=0 if Aspir=="Fighters"
		replace SuicideAspir_2=1 if Aspir=="Suicid_fighter"
		replace SuicideAspir_2=1 if Aspir=="Suicide"

	g PrevJihad=.
		replace PrevJihad=0 if Experience=="No"
		replace PrevJihad=1 if Experience=="Yes"
		
	g PreviousJobSkilled_1=.
		replace PreviousJobSkilled_1=0 if inlist(job,2,3)==0 
		replace PreviousJobSkilled_1=1 if inlist(job,2,3)==1 //Manager; Professional Worker
	
	g PreviousJobSkilled_2=.
		replace PreviousJobSkilled_2=0 if inlist(job,2,3,7,8,9)==0 
		replace PreviousJobSkilled_2=1 if inlist(job,2,3,7,8,9)==1 //Manager; Professional Worker;Shop owner; Govt Employee; Pvt employee
		

	//Generate education dummies and set them to missing when education is missing
	tab isis_education, gen(educ)
	foreach var of varlist educ1 - educ3{
	replace `var'=. if educ4
	}

	//Generate religious level dummies and set them to missing when religious level is missing
	gen religious1 = ReligiousLevel=="Basic" if ReligiousLevel!="Unknown" & !missing(ReligiousLevel)
	gen religious2 = ReligiousLevel=="Intermediary" if ReligiousLevel!="Unknown" & !missing(ReligiousLevel)
	gen religious3 = ReligiousLevel=="Advanced" if ReligiousLevel!="Unknown" & !missing(ReligiousLevel)

	//Generate skill level dummies and set them to missing when job is missing
	gen skill1 = !inlist(job,2,3,7,8,9) if !missing(job)
	gen skill2 = inlist(job,2,3) if !missing(job)
	gen skill3 = inlist(job,7,8,9) if !missing(job)

******************************* GENERATE TABLES *********************

*Sample restrictions

	drop if isis_age <16 | isis_age>60
	drop if Country_resid=="Syria"
	
	*generate tables
	capture drop isis_age2
	g isis_age2=isis_age/100

	*Create a few other variables
	encode ReligiousLevel,g(ReligiousLevel_n)
		recode ReligiousLevel_n (4=.) (2=1) (3=2) (1=3)	
	
	
	*dummies for missing values
	g skill_m=missing(job)
	g religious_m=missing(ReligiousLevel) + (ReligiousLevel=="Unknown")
	g educ_m=missing(isis_education) + (educ4==1)
	g jihad_m=missing(Experience)+ (Experience=="Unknown")
	g parent_m=missing(Number_children)
	g married_m=missing(CivilStatus) + (CivilStatus=="Unknown")
	g age_m=missing(isis_age) 


	gen age1 = inrange(isis_age,0,20) if !missing(isis_age)
	gen age2 = inrange(isis_age,20,30) if !missing(isis_age)
	gen age3 = isis_age>30 if !missing(isis_age)
	
	gen job1 = inlist(job,94,95,96,97) if !missing(job)
	gen job2 = inlist(job,4,5,6) if !missing(job)
	gen job3 = inlist(job,7,8,9) if !missing(job)
	gen job4 = inlist(job,2,3) if !missing(job)

	la var 	PreviousJobSkilled_1 		 "Skill Job (1)"
	la var 	PreviousJobSkilled_2  		 "Skill Job (2)"
	la var 	isis_age  		 			 "Age"
	la var 	isis_age2  		 			 "Age"
	la var 	Married 					 "Married"
	la var 	Parent  					 "Parent"
	la var 	ReligiousPlus   			 "High/Int Rel"
	la var 	PrevJihad  				 "Previous Jihad"
	la var 	AdminAspir 					 "Admin aspiration"
	la var 	FighterAspir 				 "Fighter aspiration"	
	la var 	SuicideAspir	 		     "Suicider aspiration"
	la var  PrimEduc					 "Primary Ed."
	la var  SecEduc					 	 "Second. Ed."
	la var  SecTerEduc					 "Sec/Ter Ed."
	la var  TerEduc						 "Tertiary Ed."
	la var  job1						 "No Prev. Job, Student, Retired or Illegal"
	la var  job2						 "Prev. Job - Craftsperson, Manual/Ag work, Security"
	la var  job3						 "Prev. Job - Shop owner, Employee"
	la var  job4						 "Prev. Job - Manager, Prof. Worker"
	la var  age1						 "Age <= 20 years"
	la var  age2						 "Age 21 -30 years"
	la var  age3						 "Age 31+ years"
	la var  educ1						 "Primary Education"
	la var  educ2						 "Secondary Education"
	la var  educ3						 "Tertiary Education"
	la var religious1					 "Low Religiosity Level"
	la var religious2					 "Medium Religiosity Level"
	la var religious3					 "High Religiosity Level"
	la var skill2					 	 "Manager, Prof. Worker"
	la var skill3					 	 "Shop owner, Employee"	

	rename AdminAspir AdminAsp
	rename SuicideAspir SuicideAsp
	rename FighterAspir FighterAsp
	
	global xlist age1 age2 age3 educ1 educ2 educ3 religious1 religious2 religious3 job1 job2 job3 job4 PrevJihad AdminAsp FighterAsp SuicideAsp

	keep $xlist 
	
	foreach var of varlist $xlist{
		gen `var'_m = `var'
		gen `var'_s = `var'
		gen `var'_n = `var'
	}	
	
	gen id = 1 
		
	collapse (mean) *_m (semean) *_s (count) *_n, by(id)
	
	reshape long $xlist , i(id) j(column) string
	
	drop id column
	
	xpose, clear varname
	
	order _varname v1 v3 v2
	
	rename _varname varname
	rename v1 mean
	rename v3 se
	rename v2 nobs
	
	replace mean = 100* mean
	replace se = 100* se
	
	tostring mean, gen(meanstr) force format(%9.1fc)  
	tostring se, gen(sestr) force format(%9.1fc)  
	tostring nobs, gen(nobsstr) force format(%9.0gc)  
	
	keep varname meanstr sestr nobsstr
	
	replace varname = "\textbf{Age} \hspace{10mm} \<=20 years" 		if varname=="age1"
	replace varname = "\hspace{10mm} 21-30 years" 	if varname=="age2"
	replace varname = "\hspace{10mm} 31+" 			if varname=="age3"
	replace varname = "\textbf{Education} \hspace{10mm} Primary" 		if varname=="educ1"
	replace varname = "\hspace{10mm} Secondary" 		if varname=="educ2"
	replace varname = "\hspace{10mm} Tertiary" 		if varname=="educ3"
	replace varname = "\textbf{Religiosity Level} \hspace{10mm} Low" 			if varname=="religious1"
	replace varname = "\hspace{10mm} Medium" 			if varname=="religious2"
	replace varname = "\hspace{10mm} High" 			if varname=="religious3"
	replace varname = "\textbf{Previous Occupation} \hspace{10mm} No Job, Student, Retired or Illegal" 	if varname=="job1"
	replace varname = "\hspace{10mm} Craftsperson, Manual/Ag work, Security" 	if varname=="job2"
	replace varname = "\hspace{10mm} Shop owner, Employee" 					if varname=="job3"
	replace varname = "\hspace{10mm} Manager, Prof. Worker" 					if varname=="job4"
	replace varname = "\textbf{Jihad Experience}" if varname=="PrevJihad"
	replace varname = "\textbf{Desired Role} \hspace{10mm} Admininstrator" if varname=="AdminAsp"
	replace varname = "\hspace{10mm} Fighter" if varname=="FighterAsp"
	replace varname = "\hspace{10mm} Suicide Fighter" if varname=="SuicideAsp"

	
	dataout, save(ind_desc)  tex  replace dec(1)
	
	//Formatting Latex File Headers
	filefilter ind_desc.tex ind_desc1.tex, replace ///
	from("\BStextbf{Age}") to("\BStextbf{Age} \BS\BS ")	

	filefilter ind_desc1.tex ind_desc.tex, replace ///
	from("\BStextbf{Education}") to("\BStextbf{Education} \BS\BS ")
	
	filefilter ind_desc.tex ind_desc1.tex, replace ///
	from("\BStextbf{Religiosity Level}") to("\BStextbf{Religiosity Level} \BS\BS ")
	
	filefilter ind_desc1.tex ind_desc.tex, replace ///
	from("\BStextbf{Previous Occupation}") to("\BStextbf{Previous Occupation} \BS\BS ")
	
	filefilter ind_desc.tex ind_desc1.tex, replace ///
	from("\BStextbf{Desired Role}") to("\BStextbf{Desired Role} \BS\BS ")
	
	filefilter ind_desc1.tex ind_desc.tex, replace ///
	from("\BSsetlength{\BSpdfpagewidth}{8.5in} \BSsetlength{\BSpdfpageheight}{11in}") to("")
	
	filefilter ind_desc.tex ind_desc1.tex, replace ///
	from("\BSbegin{document}") to("")	

	filefilter ind_desc1.tex ind_desc.tex, replace ///
	from("\BSend{document}") to("")
	
	filefilter ind_desc.tex ind_desc1.tex, replace ///
	from("meanstr") to("\BStextbf{Mean}")	

	filefilter ind_desc1.tex ind_desc.tex, replace ///
	from("sestr") to("\BStextbf{Std. Error}")
	
	filefilter ind_desc.tex ind_desc1.tex, replace ///
	from("nobsstr") to("\BStextbf{N}")	

	filefilter ind_desc1.tex ind_desc.tex, replace ///
	from("varname") to("\BStextbf{Variables}")
	
	
	
	
*****************************************************************
*Table 2 Panel B: Descriptive stats of macroeconomic variables
****************************************************************

use "${outdir}/finaldata_C.dta", clear  // crosscountry data

	drop if countryname=="Syrian Arab Republic" | countryname=="Iraq" | countryname=="Syria"
	keep if year==2013
		    
	replace isis_nfighter=0 if isis_nfighter==0 | isis_nfighter==. 
    rename isis_nfighter_resid nisis
	gen     disis        = (nisis!=0)
    gen     d10isis      = (nisis>=10)  		
	gen     d33isis      = (nisis>=33)  

		
****creating unemployment variable ilo2 (replacing missing ilo1 with wdi data)

	rename unemploymenttotaloftotallaborfor unemp_tot
	generate  ilo2_unemp_tot  = ilo1_unemp	
	replace   ilo2_unemp_tot  = unemp_tot if ilo2_unemp_tot==. & unemp_tot!=.
	replace   ilo2_unemp_tot  = ilo2_unemp_tot/100
		
	la var ilo2_unemp_tot "Unemployment rate"

	save "${outdir}/inter_ext.dta",		replace
	
	replace pew_muslims_n = pew_muslims_n/1000000
	replace pop2014 = pop2014/1000000
			
	global xlist dist_tosyria gdp_pc hdi pew_muslims_n pop2014 corruption_index  political_rights fraction_e fraction_l fraction_r avg_religiosity GRI SHI

	sutex $xlist, lab nobs key(descstat) replace ///
	file(descriptive.tex) title("Panel A: Country Level") minmax
	
use "${outdir}/finaldata_CE.dta", clear  ///crosscountry data

	*drop if education_level==4

	gen wage_tertx = wage1lag3 if education_level == 3
	bys ctry: egen wage_tert = mean(wage_tertx)
	
	gen wage_rel = wage1lag3 / wage_tert
		
	la var wage_rel				"Relative Wage"
	la var ilo2_unemp_educ 		"Unemployment rate"
	
	sutex wage_rel ilo2_unemp_educ , lab nobs key(descstat) append ///
	file(descriptive.tex) title("Panel B: Country-Education Level") minmax
	

***************************************************************
* Table 3: Unemployment and foreign recruitment into Daesh
***************************************************************


* 3 panels that are manually combined
 
 
 // FIRST THREE COLUMNS BASED ON Cross Country DATA

	*Creating globals
		glo options7   dec(3) nocons word se lab nonotes nor2
		glo xlist1   ="ilo2_unemp_educ log_pop_tot log_pop_muslim_pew log_gdp_pc  log_dist_tosyria"
		glo xpol1    ="political_rights fraction_e fraction_l fraction_r"
		glo xpol2    ="political_rights corruption_index"
		glo rel1     ="avg_religiosity"
		glo rel2     ="GRI SHI" 
		glo region   ="reg_eastasia reg_southasia reg_eca reg_lac reg_africa reg_otheroecd"
		glo sortlist ="$xlist1 hdi gini political_rights fraction_e fraction_l fraction_r corruption_index $rel1 $rel2"
				
	*Get data
		use "${outdir}/expert_data.dta", clear
	
		rename iso3 countrycode
		rename Isis_count expert_estimates
		sort countrycode

		merge 1:1 countrycode using "${outdir}/intermediate_ext.dta" // see 4results_appendix_sarur.do for prep code 
		replace expert_estimates=0 if expert_estimates==.
		gen bk_disis=(expert_estimates>0)
		cap drop _merge
		
	*Generate log variables and residuals
		gen expert_estimates_log =log(expert_estimates+1)
		gen nisis_log            =log(nisis+1)
		gen nisis_slog            =log(nisis)
		
		reg nisis_log expert_estimates_log 
		predict log_residual, res
		
		reg disis bk_disis
		predict d_residual, res
		
		ren ilo2_unemp_tot ilo2_unemp_educ
		label var ilo2_unemp_educ "Unemployment rate"
	
	*Drop South Africa outlier
		drop if countrycode=="ZAF" 

	*Panel A Column 1, extensive margin, replication of Benmelech & Klor, with our data on LHS
		reg disis $xlist1 , vce(robust) 
		mean disis if e(sample) // should be only for countries close to Syria
		local mean=round(_b[disis],.001)   
		reg disis $xlist1 , vce(robust) 
		local adjr=round(e(r2),.01)
		local adjr : di %6.0g `adjr'
		local clust =e(N)
			outreg2 using main_fullsample_a,  tex(frag) $options7 sortvar($sortlist) replace drop (reg* reg_otheroecd reg_lac ) ctitle("$\mathbbm{1}_{N_c>0}$") addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, N, Country FE, N, Adj. R-squared, `adjr' ) 
		
	*Panel A Column 2, intenisive margin (log x+1)
		reg nisis_log $xlist1 , vce(robust) 
		mean nisis_log if e(sample) // should be only for countries close to Syria
		local mean=round(_b[nisis_log],.001)   
		reg nisis_log $xlist1 , vce(robust) 
		local adjr=round(e(r2),.01)
		local adjr : di %6.0g `adjr'
		local clust =e(N)
			outreg2 using main_fullsample_a,  tex(frag) $options7 sortvar($sortlist) append drop (reg* reg_otheroecd reg_lac ) ctitle("$ log(N_c+1) $") addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, N, Country FE, N, Adj. R-squared, `adjr' ) 
		
 
	*Panel A Column 3, intenisive margin (log x)
		reg nisis_slog $xlist1 , vce(robust) 
		mean nisis_slog if e(sample) // should be only for countries close to Syria
		local mean=round(_b[nisis_slog],.001)   
		reg nisis_slog $xlist1 , vce(robust) 
		local adjr=round(e(r2),.01)
		local adjr : di %6.0g `adjr'
		local clust =e(N)
			outreg2 using main_fullsample_a,  tex(frag) $options7 sortvar($sortlist) append drop (reg* reg_otheroecd reg_lac ) ctitle("$ log(N_c) $") addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, N, Country FE, N, Adj. R-squared, `adjr' ) 
		
  
 
 // Getting PANEL DATA 
 
use "${outdir}/finaldata_CE.dta", clear 

		data_preamble //Invoking data prep program to clean data and create variables
		
		//Altering data variables
		la var unemp_logdistance             "\textbf{Interaction between unemployment and} \\ Distance to Syria (log)"

	    global unresc_all ="log_dist_tosyria log_gdp_pc log_pop_muslim_pew log_pop_tot political_rights corruption_index"
	    global resc_fe  ="unemp_logdistance unemp_resc_loggdp unemp_resc_logmuslimpop unemp_resc_logpop_tot unemp_resc_politicalrts unemp_resc_corruption"
        global options1 ="dec(3) nocons word se lab nor2"
		global sortlist ="ilo2_unemp_educ log_pop_tot log_pop_muslim_pew log_gdp_pc  log_dist_tosyria log_ilo2_pop log_wage1lag3 log_wage2lag3 log_wage2lag6 $unresc_all unemp_secondary unemp_tertiary $resc_fe"
		global drop_resc="education_level ctry* ctrydummy1-ctrdummy168 educ2 educ3 1b.education_level#co.ilo2_unemp_educ  o.resc_corruption_index o.resc_log_pop_tot o.ilo2_unemp_educ o.hdi o.gini o.resc_political_rights o.resc_fraction_language o.resc_fraction_religion o.resc_fraction_ethnic o.resc_log_pop_muslim_pew o.log_dist_tosyria o.resc_log_gdp_pc"
        global options2  ctitle("$ log N_{ce}$") nonotes	

		
// PANEL A (no moulton here as > 32 clusters)
			local sample1="if logn_educ!=."
				
				*Column 4 - no FE
					*Get mean
					xi: reg logn_educ ilo2_unemp_educ `sample1',  vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xi: reg logn_educ ilo2_unemp_educ `sample1', vce(cluster ctry)
						local clust= e(N_clust)
					
					*Get adjusted R2 -- as moulton doesn't give adjusted R2
					xi: reg logn_educ ilo2_unemp_educ `sample1',  vce(cluster ctry)
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'		
						
					outreg2 using main_fullsample_a.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, N, Country FE, N, Adj. R-squared, `adjr') 


						
				*Column 5 - add educ FE
					*Get mean
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', vce(cluster ctry)
						local clust= e(N_clust)
						
					*Get Adjusted r2
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  vce(cluster ctry)			
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	
			
			
					outreg2 using main_fullsample_a.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, N, Adj. R-squared, `adjr') 



						
				*Column 6 - add educ and country FE
					// BRL doesn't run with covariates that don't vary at cluster level (so no FE)
					// wild boostrap runs but p-value 0, so dropping those two here
					*Get mean
					xtreg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', fe vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xtreg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', fe vce(cluster ctry)
						local clust= e(N_clust)
				
					*Get adjusted r2
					areg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', absorb(ctry) vce(cluster ctry)		
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'						
					
					xtreg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', fe vce(cluster ctry)		

													
					outreg2 using main_fullsample_a.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, Y, Adj. R-squared, `adjr') 


						
				*Column 7 - both FE and add labor force
					*Get mean
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', fe vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', fe vce(cluster ctry)
						local clust= e(N_clust)

					*Get adjusted r2
					areg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', absorb(ctry) vce(cluster ctry)		
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	
						
					*Get b and se
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', fe vce(cluster ctry)			

					outreg2 using main_fullsample_a.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, Y, Adj. R-squared, `adjr') 
								
						

				*column 8 - add distance*UE interaction
					*Get mean
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 unemp_logdistance `sample1', fe vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 unemp_logdistance `sample1', fe vce(cluster ctry)
						local clust= e(N_clust)
						
					*Get adjusted r2
					areg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 unemp_logdistance `sample1', absorb(ctry) vce(cluster ctry)		
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	
						
					*Get adjusted b and se
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 unemp_logdistance `sample1', fe vce(cluster ctry)			

					outreg2 using main_fullsample_a.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean Outcome", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, Y, Adj. R-squared, `adjr') 
								
									
					
				
				
// PANEL B: CLOSE COUNTRIES
			local sample1=`"if  quart_dist1==1  "' 
		
				*Column 4 - no FE
					*Get mean
					xi: reg logn_educ ilo2_unemp_educ `sample1',  vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xi: reg logn_educ ilo2_unemp_educ `sample1', vce(cluster ctry)
						local clust= e(N_clust)
					
					*Get adjusted R2 -- as moulton doesn't give adjusted R2
					xi: reg logn_educ ilo2_unemp_educ `sample1',  vce(cluster ctry)
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	

					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)			
						
					outreg2 using main_fullsample_b.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  replace addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, N, Country FE, N, Adj. R-squared, `adjr') 


						
				*Column 5 - add educ FE
					*Get mean
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', vce(cluster ctry)
						local clust= e(N_clust)
						
					*Get adjusted r2
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  vce(cluster ctry)			
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	
						
					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)					
			
					outreg2 using main_fullsample_b.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, N, Adj. R-squared, `adjr') 



						
				*Column 6 - add educ and country FE
					// BRL doesn't run with covariates that don't vary at cluster level (so no FE)
					// wild boostrap runs but p-value 0, so dropping those two here
					*Get mean
					xtreg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', fe vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xtreg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', fe vce(cluster ctry)
						local clust= e(N_clust)
				
					*Get adjusted r2
					areg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', absorb(ctry) vce(cluster ctry)		
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	
						
					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ educ2 educ3 ctrydummy* `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)					
										
					outreg2 using main_fullsample_b.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, Y, Adj. R-squared, `adjr') 


						
				*Column 7 - both FE and add labor force
					*Get mean
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', fe vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', fe vce(cluster ctry)
						local clust= e(N_clust)

					*Get adjusted b and se
					areg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', absorb(ctry) vce(cluster ctry)			
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'		
						
					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 ctrydummy* `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)					
		

					outreg2 using main_fullsample_b.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, Y, Adj. R-squared, `adjr') 
					
				

					
// PANEL C: DISTANT COUNTRIES
			
			local sample1=`"if  quart_dist4==1  "' 

				*Column 4 - no FE
					*Get mean
					xi: reg logn_educ ilo2_unemp_educ `sample1',  vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xi: reg logn_educ ilo2_unemp_educ `sample1', vce(cluster ctry)
						local clust= e(N_clust)
					
					*Get adjusted R2 -- as moulton doesn't give adjusted R2
					xi: reg logn_educ ilo2_unemp_educ `sample1',  vce(cluster ctry)
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	

					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)			
						
					outreg2 using main_fullsample_c.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  replace addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, N, Country FE, N, Adj. R-squared, `adjr') 


						
				*Column 5 - add educ FE
					*Get mean
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', vce(cluster ctry)
						local clust= e(N_clust)
						
					*Get adjusted r2
					xi: reg logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  vce(cluster ctry)			
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	
						
					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ educ2 educ3 `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)					
			
					outreg2 using main_fullsample_c.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, N, Adj. R-squared, `adjr') 
	
				*Column 6 - add educ and country FE
					// BRL doesn't run with covariates that don't vary at cluster level (so no FE)
					// wild boostrap runs but p-value 0, so dropping those two here
					*Get mean
					xtreg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', fe vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xtreg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', fe vce(cluster ctry)
						local clust= e(N_clust)
				
					*Get adjusted r2
					areg logn_educ ilo2_unemp_educ educ2 educ3 `sample1', absorb(ctry) vce(cluster ctry)		
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'	
						
					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ educ2 educ3 ctrydummy* `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)					
										
					outreg2 using main_fullsample_c.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, Y, Adj. R-squared, `adjr') 


				*Column 7 - both FE and add labor force
					*Get mean
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', fe vce(cluster ctry)
						mean nisis_educ if e(sample) // should be only for countries close to Syria
						local mean=int(_b[nisis_educ]*10)/10
					*Get n clusters
					xtreg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', fe vce(cluster ctry)
						local clust= e(N_clust)

					*Get adjusted b and se
					areg logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 `sample1', absorb(ctry) vce(cluster ctry)			
						local adjr=round(e(r2_a),.001)
						local adjr : di %7.0g `adjr'		
						
					*Get Moulton b and se  
					moulton logn_educ ilo2_unemp_educ log_ilo2_pop educ2 educ3 ctrydummy* `sample1',  cl(ctry) moulton
						local b1=round(_b[ilo2_unemp_educ],0.001)
						local se1=round(_se[ilo2_unemp_educ],0.001)					
		

					outreg2 using main_fullsample_c.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc)  append addtext("Mean $ N_{ce} $", `mean', Number of Countries, `clust', Education Dummies, Y, Country FE, Y, Adj. R-squared, `adjr') 					
				
				

		
***********************************
*Table 4: Distance interaction
***********************************
              	
		use "${outdir}/finaldata_CE.dta", clear 
		
		data_preamble //Invoking data prep program to clean data and create variables
		
		//Altering variable labels
		la var unemp_logdistance             "\textbf{Interaction between unemployment and}\\Distance to Syria (log)"

	    global unresc_all ="log_dist_tosyria log_gdp_pc log_pop_muslim_pew log_pop_tot political_rights corruption_index"
	    global resc_fe  ="unemp_logdistance unemp_resc_loggdp unemp_resc_logmuslimpop unemp_resc_logpop_tot unemp_resc_politicalrts unemp_resc_corruption"
        global options1 ="dec(3) nocons word se lab nor2"
		global sortlist ="ilo2_unemp_educ log_ilo2_pop log_wage1lag3 log_wage2lag3 log_wage2lag6 $unresc_all unemp_secondary unemp_tertiary $resc_fe unemp_median_dist1 unemp_median_dist2 unemp_tercile_dist1 unemp_tercile_dist2 unemp_tercile_dist3 unemp_quart_dist1 unemp_quart_dist2 unemp_quart_dist3 unemp_quart_dist4"
		global drop_resc="ctrydummy1-ctrdummy168 educ2 educ3 1b.education_level#co.ilo2_unemp_educ  o.resc_corruption_index o.resc_log_pop_tot o.ilo2_unemp_educ o.hdi o.gini o.resc_political_rights o.resc_fraction_language o.resc_fraction_religion o.resc_fraction_ethnic o.resc_log_pop_muslim_pew o.log_dist_tosyria o.resc_log_gdp_pc"
				
*********** Table with different splits **************	
		cap drop sample

		*Continuous interaction
		global options2  ctitle("$ log N_{ce}$" ) nonotes 
		
	*Column 1
		xtreg logn_educ  log_ilo2_pop ilo2_unemp_educ  unemp_logdistance educ2 educ3 ,  fe vce(cluster ctry)  
		cap drop sample
		gen sample = e(sample)
		sa "${outdir}/reg_sample.dta", replace
		mean nisis_educ if e(sample) // should be only for countries close to Syria
		local mean=int(_b[nisis_educ]*10)/10
		xtreg logn_educ  log_ilo2_pop ilo2_unemp_educ  unemp_logdistance educ2 educ3 , fe vce(cluster ctry)  		
		local clust= e(N_clust)
		areg logn_educ  log_ilo2_pop ilo2_unemp_educ  unemp_logdistance educ2 educ3 , absorb(ctry)  vce(cluster ctry)  
		local adjr =int(e(r2_a)*100)/100
		local adjr : di %3.2g `adjr'
		xtreg logn_educ   log_ilo2_pop ilo2_unemp_educ  unemp_logdistance educ2 educ3 , fe vce(cluster ctry)  
		outreg2 using table5_2.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc ctrydummy*) replace  addtext("Mean $ N_{ce} $", `mean',  Country FE, Y, Number of Countries, `clust', Education Dummies, Y, Adj. R-squared, `adjr') 

		*Median- split for Total
		global options2  ctitle("$ log N_{ce}$","Total") nonotes 
		
	*Column 2
		xtreg logn_educ  log_ilo2_pop unemp_median_dist1 unemp_median_dist2 educ2 educ3 ,  fe vce(cluster ctry)  
		mean nisis_educ if e(sample) // should be only for countries close to Syria
		local mean=int(_b[nisis_educ]*10)/10
		xtreg logn_educ  log_ilo2_pop unemp_median_dist1 unemp_median_dist2 educ2 educ3 , fe vce(cluster ctry)  		
		local clust= e(N_clust)
		areg logn_educ  log_ilo2_pop unemp_median_dist1 unemp_median_dist2 educ2 educ3 , absorb(ctry)  vce(cluster ctry)  
		local adjr =int(e(r2_a)*100)/100
		local adjr : di %3.2g `adjr'
		xtreg logn_educ   log_ilo2_pop unemp_median_dist1 unemp_median_dist2 educ2 educ3 , fe vce(cluster ctry)  
		outreg2 using table5_2.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc ctrydummy*) append  addtext("Mean $ N_{ce} $", `mean',  Country FE, Y, Number of Countries, `clust', Education Dummies, Y, Adj. R-squared, `adjr') 

		
		*Tercile- split for Total
		global options2  ctitle("$ log N_{ce}$","Total") nonotes 

	*Column 3
		xtreg logn_educ  log_ilo2_pop unemp_tercile_dist1 unemp_tercile_dist2 unemp_tercile_dist3 educ2 educ3 ,  fe vce(cluster ctry)  
		mean nisis_educ if e(sample) // should be only for countries close to Syria
		local mean=int(_b[nisis_educ]*10)/10
		xtreg logn_educ  log_ilo2_pop unemp_tercile_dist1 unemp_tercile_dist2 unemp_tercile_dist3 educ2 educ3 , fe vce(cluster ctry)  		
		local clust= e(N_clust)
		areg logn_educ  log_ilo2_pop unemp_tercile_dist1 unemp_tercile_dist2 unemp_tercile_dist3 educ2 educ3 , absorb(ctry)  vce(cluster ctry)  
		local adjr =int(e(r2_a)*100)/100
		xtreg logn_educ   log_ilo2_pop unemp_tercile_dist1 unemp_tercile_dist2 unemp_tercile_dist3 educ2 educ3 , fe vce(cluster ctry)  
		outreg2 using table5_2.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc ctrydummy*) append  addtext("Mean $ N_{ce} $", `mean', Country FE, Y, Number of Countries, `clust', Education Dummies, Y, Adj. R-squared, `adjr') 

		*Quartile- split for Total
		global options2  ctitle("$ log N_{ce}$","Total") nonotes
		
	*Column 4
		xtreg logn_educ  log_ilo2_pop unemp_quart_dist1 unemp_quart_dist2 unemp_quart_dist3 unemp_quart_dist4 educ2 educ3 ,  fe vce(cluster ctry)  
		mean nisis_educ if e(sample) // should be only for countries close to Syria
		local mean=int(_b[nisis_educ]*10)/10
		xtreg logn_educ  log_ilo2_pop unemp_quart_dist1 unemp_quart_dist2 unemp_quart_dist3 unemp_quart_dist4 educ2 educ3 , fe vce(cluster ctry)  		
		local clust= e(N_clust)
		areg logn_educ  log_ilo2_pop unemp_quart_dist1 unemp_quart_dist2 unemp_quart_dist3 unemp_quart_dist4 educ2 educ3 , absorb(ctry)  vce(cluster ctry)  
		local adjr=round(e(r2_a),.01)
		local adjr : di %3.2g `adjr'
		xtreg logn_educ   log_ilo2_pop unemp_quart_dist1 unemp_quart_dist2 unemp_quart_dist3 unemp_quart_dist4 educ2 educ3 , fe vce(cluster ctry)  
		outreg2 using table5_2.docx  , tex(frag) $options1 $options2 noni sortvar($sortlist)  drop ($drop_resc ctrydummy*) append  addtext("Mean $ N_{ce} $", `mean', Country FE, Y, Number of Countries, `clust', Education Dummies, Y, Adj. R-squared, `adjr') 

	
